import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import pinia from './store'
import api from '@/http/api'
import localApi from '@/http/localHttp'
import tipMessage from '@/utils/tipMessage'
import './style/global.scss'
import '@/assets/iconfont/iconfont.css'
import './assets/font/font.css'
import 'xgplayer/dist/index.min.css'
import linkTargetBlank from '@/directives/linkTargetBlank'

/**
 * 格式化时间
 */
import moment from 'moment'
import 'moment/dist/locale/zh-cn'

/**
 * element-plus
 */
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import zhCn from 'element-plus/es/locale/lang/zh-cn'

/**
 * echarts
 */
import echarts from 'vue-echarts'
import { use } from 'echarts/core'
import { CanvasRenderer } from 'echarts/renderers'
import { BarChart, PieChart, ScatterChart, PictorialBarChart, LineChart, GaugeChart, RadarChart, SunburstChart } from 'echarts/charts'
import { GridComponent, TooltipComponent, TitleComponent, LegendComponent, DataZoomComponent, ToolboxComponent, GraphicComponent, PolarComponent } from 'echarts/components'
use([
  PolarComponent,
  SunburstChart,
  RadarChart,
  CanvasRenderer,
  BarChart,
  PieChart,
  ScatterChart,
  PictorialBarChart,
  LineChart,
  GaugeChart,
  GridComponent,
  TooltipComponent,
  TitleComponent,
  LegendComponent,
  DataZoomComponent,
  ToolboxComponent,
  GraphicComponent
])

const app = createApp(App).use(pinia).directive('link-target-blank', linkTargetBlank)

//进行动态路由注册 ，必须是在use pinia 之后，不然没办法用
import useUserMessage from '@/store/userMessage.js'
useUserMessage().updateRouteList()

//需要在pinia 动态添加完路由之后添加router，不然router已经生成了，刷新页面之后直接访问动态的路由会直接跳转到404，pinia后续再加路由没有意义了
app.use(router)

app.config.globalProperties.$http = api
app.config.globalProperties.$localHttp = localApi
app.config.globalProperties.$tipMessage = tipMessage
app.config.globalProperties.$moment = moment
app.config.globalProperties.$moment.locale('zh-cn')
app.use(ElementPlus, { locale: zhCn })
app.component('v-echarts', echarts)
app.mount('#app')
